package com.chuzhiyun.chengguoxy.feature.mine;

import android.view.View;
import com.chuzhiyun.chengguoxy.databinding.FragmentMineBinding;
import com.chuzhiyun.chengguoxy.feature.base.BaseFragment;
import com.chuzhiyun.chengguoxy.feature.bean.UserInfoBean;
import com.chuzhiyun.chengguoxy.feature.login.LoginActivity;
import com.chuzhiyun.chengguoxy.feature.welcome.WelcomeActivity;
import com.chuzhiyun.chengguoxy.global.Config;
import com.chuzhiyun.chengguoxy.global.UserConfig;
import com.chuzhiyun.chengguoxy.network.NetApi;
import com.chuzhiyun.chengguoxy.network.NetService;
import com.chuzhiyun.chengguoxy.network.StringNetCallback;
import com.chuzhiyun.chengguoxy.utlis.CustomClickListener;
import com.google.gson.Gson;
import com.hjq.toast.ToastUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cookie.store.CookieStore;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.RxSPTool;
import com.vondear.rxtool.view.RxToast;

import java.util.Objects;


public class MineFragment extends BaseFragment<FragmentMineBinding> {

    @Override
    public void initView(View view) {
        binding.quteText.setOnClickListener(new CustomClickListener() {
            @Override
            protected void onSingleClick() {
                ToastUtils.show("退出");
                CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
                cookieStore.removeAllCookie();
                RxSPTool.remove(requireActivity(),Config.SP_TOKEN);
                RxActivityTool.skipActivityAndFinishAll(requireActivity(), LoginActivity.class);
            }
        });
        binding.bindText.setOnClickListener(new CustomClickListener() {
            @Override
            protected void onSingleClick() {

            }
        });
        getUserInfo();
    }

    private void getUserInfo(){
        String url = NetApi.getStudentInfo();
        NetService.getInstance().get(url, new StringNetCallback() {
            @Override
            public void onSuccess(String response, int statusCode) throws Exception {
                System.out.println(response);
                if (statusCode==200){
                    Gson gson = new Gson();
                    UserInfoBean bean = gson.fromJson(response,UserInfoBean.class);
                    binding.nameText.setText(UserConfig.getInstance().getName());
                }
            }

            @Override
            public void onError(String error) {
                System.out.println(error);
            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public void setListener() {

    }
}